import { ApiRes, GoodItem, HotGoods, HotBrand, HomeProduct, SpecialItem } from '@/types/data';
import { BannerItem } from '@/types/data';
import request from '@/utils/request';
import { defineStore } from 'pinia'
import { delay } from '@/utils/delay'

const useHome = defineStore('home', {
  state() {
    return {
      list: [] as BannerItem[],
      newGoodList: [] as GoodItem[],
      hotGoodList: [] as HotGoods[],
      HotBrandList: [] as HotBrand[],
      productList: [] as HomeProduct[],
      specialList: [] as SpecialItem[]
    }
  },
  actions: {
    async getBanners() {
      const res = await request.get<ApiRes<BannerItem[]>>('/home/banner')
      // console.log(res.data.result)
      this.list = res.data.result
    },
    async getNewList() {
      // await delay(3000)
      const res = await request.get<ApiRes<GoodItem[]>>('/home/new')
      // console.log(res.data)
      this.newGoodList = res.data.result
    },
    async getHotList() {
      // await delay(3000)
      const res = await request.get<ApiRes<HotGoods[]>>('/home/hot')
      // console.log(res.data)
      this.hotGoodList = res.data.result
    },
    async getBrandList() {
      // await delay(3000)
      const res = await request.get<ApiRes<HotBrand[]>>('/home/brand')
      console.log(res.data.result)
      this.HotBrandList = res.data.result
    },
    async getProductList() {
      const res = await request.get<ApiRes<HomeProduct[]>>('/home/goods')
      // console.log(res.data.result)
      this.productList = res.data.result
    },
    async getSpecialList() {
      const res = await request.get<ApiRes<SpecialItem[]>>('/home/special')
      console.log(res.data.result)
      this.specialList = res.data.result
    },
  },
  getters: {}
})
export default useHome